home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 15 / BBS in a box XV-2.iso / Files II / Prog / B-C / C++ FAQ Reference 1.0.sit / C++ FAQ Reference 1.0.rsrc / TEXT_1050.txt < prev    next >
Encoding:
Text File  |  1993-06-30  |  1.2 KB  |  21 lines

  1. Take these classes as examples:
  2.     class B { /*...*/ };
  3.     class D_priv : private   B { /*...*/ };
  4.     class D_prot : protected B { /*...*/ };
  5.     class D_publ : public    B { /*...*/ };
  6.     class Client { B b; /*...*/ };
  7.  
  8. Public and protected parts of B are 'private' in D_priv, and are 'protected' in D_prot.  In D_publ, public parts of B are public (D_prot is-a-kind-of-a B), and protected parts of B remain protected in D_publ.  Naturally *none* of the subclasses can access anything that is private in B.  Class 'Client' can't even access the protected parts of B (ie: it's 'sealed off').
  9.  
  10. It is often the case that you want to make some but not all inherited member functions public in privately/protectedly derived classes.  Ex: to make member fn B::f(int,char,float) public in D_prot, you would say:
  11.     class D_prot : protected B {
  12.       //...
  13.     public:
  14.       B::f;    //note: not  B::f(int,char,float)
  15.     };
  16.  
  17. There are limitations to this technique (can't distinguish overloaded names, and you can't make a feature that was 'protected' in the base 'public' in the derived).  Where necessary, you can get around these by a call-through fn:
  18.     class D_prot : protected B {
  19.     public:
  20.       short f(int i, char c, float f) { return B::f(i,c,f); }
  21.     };